home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000098_icon-group-sender _Thu Apr 21 06:30:52 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Sun, 24 Apr 1994 13:54:22 MST
  2. Path: ucbvax!agate!ihnp4.ucsd.edu!swrinde!emory!europa.eng.gtefsd.com!MathWorks.Com!noc.near.net!hopscotch.ksr.com!tim
  3. From: tim@ksr.com (Tim Peters)
  4. Newsgroups: comp.lang.icon
  5. Subject: Re: generate keys of a table?
  6. Message-Id: <2p56is$k0t@hopscotch.ksr.com>
  7. Date: 21 Apr 94 06:30:52 GMT
  8. References: <MIKE.94Apr20181417@majestix.cs.uoregon.edu>
  9. Distribution: inet
  10. Organization: Kendall Square Research
  11. Lines: 36
  12. Nntp-Posting-Host: kaos.ksr.com
  13. Apparently-To: icon-group@cs.arizona.edu
  14. Status: R
  15. Errors-To: icon-group-errors@cs.arizona.edu
  16.  
  17. mike@majestix.cs.uoregon.edu (Mike Haertel) writes:
  18.  
  19. >Is there a way to enumerate keys of a table (not the entries)?
  20.  
  21. "key" is builtin generator that does what you're after.  See "The Icon
  22. Programming Language", 2nd edition, pgs 74-75.  If you have a very old
  23. version of Icon, "key" might not be in it.
  24.  
  25. Here's an example:
  26.  
  27. procedure main()
  28.    local t, i
  29.    t := table()
  30.    every i := 1 to 10 do t[i] := "abcdefghij"[i]
  31.    every writes( right(!t, 3) )
  32.    write()
  33.    every writes( right(key(t), 3) )
  34.    write()
  35. end
  36.  
  37. And here's its output:
  38.  
  39.   e  b  j  g  d  a  i  f  c  h
  40.   5  2 10  7  4  1  9  6  3  8
  41.  
  42. key(table) generates table's keys in an arbitrary order, but so long as
  43. you don't fiddle with table in the meantime, it's the same arbitrary
  44. order that !table uses for generating table's entries.
  45.  
  46. BTW, I believe that if Dr. Griswold had it to do all over again, !table
  47. would generate keys instead of entries.
  48.  
  49. why-languages-should-be-implemented-but-never-used<wink>-ly y'rs  - tim
  50.  
  51. Tim Peters   tim@ksr.com
  52. not speaking for Kendall Square Research Corp
  53.